package cn.wen.eeayjoke.ui.pager;

import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cn.wen.base.adapter.recyclerview.QuickRecyclerAdapter;
import cn.wen.base.adapter.recyclerview.QuickRecyclerViewHolder;
import cn.wen.base.decoration.LinearItemDecoration;
import cn.wen.base.view.SwipeMenuLayout;
import cn.wen.core.ui.AppFragment;
import cn.wen.eeayjoke.R;

/**
 * Created by Administrator on 2018/7/7.
 */

public class PagerFmtTwo extends AppFragment {

    private MyRecyclerView mRecyclerView;

    @Override
    protected Object getContentLayout() {
        return R.layout.fmt_pager_two;
    }

    @Override
    protected void initView(View contentView) {
        mRecyclerView = contentView.findViewById(R.id.recycler_view);
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            list.add("i-->" + i);
        }
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getAppActivity()));
        mRecyclerView.addItemDecoration(new LinearItemDecoration(getAppActivity()));
        mRecyclerView.setAdapter(new QuickRecyclerAdapter<String>(getAppActivity(), list, R.layout.item_main_test) {
            @Override
            protected void convert(final QuickRecyclerViewHolder holder, final String item, final int position) {
                holder.setText(R.id.tv, item);
                holder.setOnClickListener(R.id.tv, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getAppActivity(), "" + item, Toast.LENGTH_SHORT).show();
                    }
                });
                holder.setOnClickListener(R.id.tv_delete, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        remove(item);
                        //在列表里，点击侧滑菜单上的选项时，如果想让侧划菜单同时关闭，调用这句话
                        if (holder.getView(R.id.delete_swipe) instanceof SwipeMenuLayout) {
                            ((SwipeMenuLayout) holder.getView(R.id.delete_swipe)).quickClose();
                        }
                    }
                });
            }
        });
    }
}
